package top.xinsix.est.controller;

import top.xinsix.est.constants.ResultEnum;
import top.xinsix.est.dto.EvaluateDto;
import top.xinsix.est.dto.UsersDto;
import top.xinsix.est.service.EvaluateService;
import top.xinsix.est.service.UsersService;
import top.xinsix.est.tools.EmptyUtils;
import top.xinsix.est.tools.Result;
import top.xinsix.est.tools.ResultUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/evaluate")
public class EvaluateController {

    @Autowired
    private EvaluateService evaluateService;
    @Autowired
    private UsersService usersService;

    @GetMapping("{id}/assessInfo")
    public Result assessInfo(@PathVariable("id") Long id){
        EvaluateDto evaluateDto = evaluateService.assessInfo(id);
        return ResultUtils.returnDataSuccess(evaluateDto);
    }

    /*@PostMapping("/assess")
    @ApiOperation(value = "估价的方法", notes = "据用户选择的故障信息，对商品维修进行评估", response = Result.class, httpMethod = "GET")
    public Result Assess(Long modelId, String optionIds, HttpServletRequest request) {
        //获取到航头的token值
        String token = request.getHeader("token");
        //根据token获取当前登录用户的信息
        UsersDto usersDto = usersService.getUserByToken(token);
        if (EmptyUtils.isEmpty(modelId)) {
            return ResultUtils.ReturnFail(ResultEnum.FAIL_PARAM.getCode(), "型号的值错误！");
        }
        if (EmptyUtils.isEmpty(optionIds)) {
            return ResultUtils.ReturnFail(ResultEnum.FAIL_PARAM.getCode(), "故障选项的值错误！");
        }
        if (EmptyUtils.isEmpty(usersDto)) {
            return ResultUtils.ReturnFail(ResultEnum.FAIL_PARAM.getCode(), "token的值错误！");
        } else {
            //调用估价方法
            EvaluateDto assess = evaluateService.Assess(modelId, optionIds, usersDto.getId());
            if(EmptyUtils.isNotEmpty(assess)){
                return ResultUtils.ReturnDataSuccess(assess);
            }
        }

        return ResultUtils.ReturnFail("调用估价方法出错！");
    }*/
}
